package carassius.GUI.Calendar;

import carassius.BLL.GregorianCalendarWithEvents;
import java.util.GregorianCalendar;

/**
 *
 * @author siebz0r
 */
public class MonthPanel
		extends javax.swing.JPanel
{
	//<editor-fold defaultstate="collapsed" desc="Fields">
	private GregorianCalendarWithEvents _calendar;
	//</editor-fold>

	//<editor-fold defaultstate="collapsed" desc="Constructors">
	public MonthPanel()
	{
		this(new GregorianCalendarWithEvents());
	}

	public MonthPanel(int year, int month)
	{
		this(new GregorianCalendarWithEvents(year,
				(month >= GregorianCalendar.JANUARY
				&& month <= GregorianCalendar.DECEMBER) ? month : new GregorianCalendar().get(GregorianCalendar.YEAR),
				1));
	}

	public MonthPanel(GregorianCalendarWithEvents calendar)
	{
		_calendar = calendar;
		initComponents();
	}
	//</editor-fold>

	//<editor-fold defaultstate="collapsed" desc="Public methods">
	public void setMonth(int month)
	{
		_calendar.set(GregorianCalendar.MONTH, month);
	}

	public int getMonth()
	{
		return _calendar.get(GregorianCalendar.MONTH);
	}

	public void addMonth()
	{
		_calendar.add(GregorianCalendar.MONTH, 1);
	}

	public void subtractMonth()
	{
		_calendar.add(GregorianCalendar.MONTH, -1);
	}

	public int getYear()
	{
		return _calendar.get(GregorianCalendar.YEAR);
	}

	public void setYear(int year)
	{
		_calendar.set(GregorianCalendar.YEAR, year);
	}
	//</editor-fold>

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        uxMonthPopupMenu = new javax.swing.JPopupMenu();
        uxJanuaryMenuItem = new javax.swing.JMenuItem();
        uxFebruaryMenuItem = new javax.swing.JMenuItem();
        uxMarchMenuItem = new javax.swing.JMenuItem();
        uxAprilMenuItem = new javax.swing.JMenuItem();
        uxMayMenuItem = new javax.swing.JMenuItem();
        uxJuneMenuItem = new javax.swing.JMenuItem();
        uxJulyMenuItem = new javax.swing.JMenuItem();
        uxAugustMenuItem = new javax.swing.JMenuItem();
        uxSeptemberMenuItem = new javax.swing.JMenuItem();
        uxOctoberMenuItem = new javax.swing.JMenuItem();
        uxNovemberMenuItem = new javax.swing.JMenuItem();
        uxDecemberMenuItem = new javax.swing.JMenuItem();
        uxMonthButton = new carassius.GUI.Calendar.MonthButton(_calendar);
        uxNextMonthButton = new javax.swing.JButton();
        uxPreviousMonthButton = new javax.swing.JButton();

        uxMonthPopupMenu.setName("uxMonthPopupMenu"); // NOI18N

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("carassius/GUI/Calendar/resources/month"); // NOI18N
        uxJanuaryMenuItem.setText(bundle.getString("0")); // NOI18N
        uxJanuaryMenuItem.setName("uxJanuaryMenuItem"); // NOI18N
        uxJanuaryMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxJanuaryMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxJanuaryMenuItem);

        uxFebruaryMenuItem.setText(bundle.getString("1")); // NOI18N
        uxFebruaryMenuItem.setName("uxFebruaryMenuItem"); // NOI18N
        uxFebruaryMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxFebruaryMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxFebruaryMenuItem);

        uxMarchMenuItem.setText(bundle.getString("2")); // NOI18N
        uxMarchMenuItem.setName("uxMarchMenuItem"); // NOI18N
        uxMarchMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxMarchMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxMarchMenuItem);

        uxAprilMenuItem.setText(bundle.getString("3")); // NOI18N
        uxAprilMenuItem.setName("uxAprilMenuItem"); // NOI18N
        uxAprilMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxAprilMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxAprilMenuItem);

        uxMayMenuItem.setText(bundle.getString("4")); // NOI18N
        uxMayMenuItem.setName("uxMayMenuItem"); // NOI18N
        uxMayMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxMayMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxMayMenuItem);

        uxJuneMenuItem.setText(bundle.getString("5")); // NOI18N
        uxJuneMenuItem.setName("uxJuneMenuItem"); // NOI18N
        uxJuneMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxJuneMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxJuneMenuItem);

        uxJulyMenuItem.setText(bundle.getString("6")); // NOI18N
        uxJulyMenuItem.setName("uxJulyMenuItem"); // NOI18N
        uxJulyMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxJulyMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxJulyMenuItem);

        uxAugustMenuItem.setText(bundle.getString("7")); // NOI18N
        uxAugustMenuItem.setName("uxAugustMenuItem"); // NOI18N
        uxAugustMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxAugustMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxAugustMenuItem);

        uxSeptemberMenuItem.setText(bundle.getString("8")); // NOI18N
        uxSeptemberMenuItem.setName("uxSeptemberMenuItem"); // NOI18N
        uxSeptemberMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxSeptemberMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxSeptemberMenuItem);

        uxOctoberMenuItem.setText(bundle.getString("9")); // NOI18N
        uxOctoberMenuItem.setName("uxOctoberMenuItem"); // NOI18N
        uxOctoberMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxOctoberMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxOctoberMenuItem);

        uxNovemberMenuItem.setText(bundle.getString("10")); // NOI18N
        uxNovemberMenuItem.setName("uxNovemberMenuItem"); // NOI18N
        uxNovemberMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxNovemberMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxNovemberMenuItem);

        uxDecemberMenuItem.setText(bundle.getString("11")); // NOI18N
        uxDecemberMenuItem.setName("uxDecemberMenuItem"); // NOI18N
        uxDecemberMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxDecemberMenuItemActionPerformed(evt);
            }
        });
        uxMonthPopupMenu.add(uxDecemberMenuItem);

        setMaximumSize(new java.awt.Dimension(120, 25));
        setMinimumSize(new java.awt.Dimension(120, 25));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(120, 25));
        setLayout(new java.awt.GridBagLayout());

        uxMonthButton.setName("uxMonthButton"); // NOI18N
        uxMonthButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxMonthButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(uxMonthButton, gridBagConstraints);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(carassius.CarassiusApp.class).getContext().getResourceMap(MonthPanel.class);
        uxNextMonthButton.setText(resourceMap.getString("uxNextMonthButton.text")); // NOI18N
        uxNextMonthButton.setName("uxNextMonthButton"); // NOI18N
        uxNextMonthButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxNextMonthButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        add(uxNextMonthButton, gridBagConstraints);

        uxPreviousMonthButton.setText(resourceMap.getString("uxPreviousMonthButton.text")); // NOI18N
        uxPreviousMonthButton.setName("uxPreviousMonthButton"); // NOI18N
        uxPreviousMonthButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uxPreviousMonthButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(uxPreviousMonthButton, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

	private void uxMonthButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxMonthButtonActionPerformed
	{//GEN-HEADEREND:event_uxMonthButtonActionPerformed
		uxMonthPopupMenu.show(uxMonthButton, 0, uxMonthButton.getHeight());
	}//GEN-LAST:event_uxMonthButtonActionPerformed

	private void uxJanuaryMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxJanuaryMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxJanuaryMenuItemActionPerformed
		setMonth(GregorianCalendar.JANUARY);
	}//GEN-LAST:event_uxJanuaryMenuItemActionPerformed

	private void uxFebruaryMenuItemActionPerformed(//GEN-FIRST:event_uxFebruaryMenuItemActionPerformed
			java.awt.event.ActionEvent evt)
	{//GEN-HEADEREND:event_uxFebruaryMenuItemActionPerformed
		setMonth(GregorianCalendar.FEBRUARY);
	}//GEN-LAST:event_uxFebruaryMenuItemActionPerformed

	private void uxMarchMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxMarchMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxMarchMenuItemActionPerformed
		setMonth(GregorianCalendar.MARCH);
	}//GEN-LAST:event_uxMarchMenuItemActionPerformed

	private void uxAprilMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxAprilMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxAprilMenuItemActionPerformed
		setMonth(GregorianCalendar.APRIL);
	}//GEN-LAST:event_uxAprilMenuItemActionPerformed

	private void uxMayMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxMayMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxMayMenuItemActionPerformed
		setMonth(GregorianCalendar.MAY);
	}//GEN-LAST:event_uxMayMenuItemActionPerformed

	private void uxJuneMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxJuneMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxJuneMenuItemActionPerformed
		setMonth(GregorianCalendar.JUNE);
	}//GEN-LAST:event_uxJuneMenuItemActionPerformed

	private void uxJulyMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxJulyMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxJulyMenuItemActionPerformed
		setMonth(GregorianCalendar.JULY);
	}//GEN-LAST:event_uxJulyMenuItemActionPerformed

	private void uxAugustMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxAugustMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxAugustMenuItemActionPerformed
		setMonth(GregorianCalendar.AUGUST);
	}//GEN-LAST:event_uxAugustMenuItemActionPerformed

	private void uxSeptemberMenuItemActionPerformed(//GEN-FIRST:event_uxSeptemberMenuItemActionPerformed
			java.awt.event.ActionEvent evt)
	{//GEN-HEADEREND:event_uxSeptemberMenuItemActionPerformed
		setMonth(GregorianCalendar.SEPTEMBER);
	}//GEN-LAST:event_uxSeptemberMenuItemActionPerformed

	private void uxOctoberMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxOctoberMenuItemActionPerformed
	{//GEN-HEADEREND:event_uxOctoberMenuItemActionPerformed
		setMonth(GregorianCalendar.OCTOBER);
	}//GEN-LAST:event_uxOctoberMenuItemActionPerformed

	private void uxNovemberMenuItemActionPerformed(//GEN-FIRST:event_uxNovemberMenuItemActionPerformed
			java.awt.event.ActionEvent evt)
	{//GEN-HEADEREND:event_uxNovemberMenuItemActionPerformed
		setMonth(GregorianCalendar.NOVEMBER);
	}//GEN-LAST:event_uxNovemberMenuItemActionPerformed

	private void uxDecemberMenuItemActionPerformed(//GEN-FIRST:event_uxDecemberMenuItemActionPerformed
			java.awt.event.ActionEvent evt)
	{//GEN-HEADEREND:event_uxDecemberMenuItemActionPerformed
		setMonth(GregorianCalendar.DECEMBER);
	}//GEN-LAST:event_uxDecemberMenuItemActionPerformed

	private void uxNextMonthButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_uxNextMonthButtonActionPerformed
	{//GEN-HEADEREND:event_uxNextMonthButtonActionPerformed
		addMonth();
	}//GEN-LAST:event_uxNextMonthButtonActionPerformed

	private void uxPreviousMonthButtonActionPerformed(//GEN-FIRST:event_uxPreviousMonthButtonActionPerformed
			java.awt.event.ActionEvent evt)
	{//GEN-HEADEREND:event_uxPreviousMonthButtonActionPerformed
		subtractMonth();
	}//GEN-LAST:event_uxPreviousMonthButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem uxAprilMenuItem;
    private javax.swing.JMenuItem uxAugustMenuItem;
    private javax.swing.JMenuItem uxDecemberMenuItem;
    private javax.swing.JMenuItem uxFebruaryMenuItem;
    private javax.swing.JMenuItem uxJanuaryMenuItem;
    private javax.swing.JMenuItem uxJulyMenuItem;
    private javax.swing.JMenuItem uxJuneMenuItem;
    private javax.swing.JMenuItem uxMarchMenuItem;
    private javax.swing.JMenuItem uxMayMenuItem;
    private carassius.GUI.Calendar.MonthButton uxMonthButton;
    private javax.swing.JPopupMenu uxMonthPopupMenu;
    private javax.swing.JButton uxNextMonthButton;
    private javax.swing.JMenuItem uxNovemberMenuItem;
    private javax.swing.JMenuItem uxOctoberMenuItem;
    private javax.swing.JButton uxPreviousMonthButton;
    private javax.swing.JMenuItem uxSeptemberMenuItem;
    // End of variables declaration//GEN-END:variables
}
